package com.ydd.moudle.me;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.taofengsdk.constant.SDKConstant;
import com.taofengsdk.video.parameters.AdParameters;
import com.ydd.R;
import com.ydd.base.BaseActivity;
import com.ydd.util.db.SPManager;

/**
 * Created by tao on 17-3-17.
 */

public class VideoSettingActivity extends BaseActivity implements View.OnClickListener {

    /**
     * UI
     */
    private RelativeLayout mWifiLayout;
    private RelativeLayout mAlwayLayout;
    private RelativeLayout mNeverLayout;
    private CheckBox mWifiBox, mAlwayBox, mNeverBox;
    private ImageView mBackView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_setting_layout);

        initView();
        init();
    }


    private void initView() {
        initHeaderView(getString(R.string.video_play_setting), true);

        mBackView = (ImageView) findViewById(R.id.back_view);
        mWifiLayout = (RelativeLayout) findViewById(R.id.wifi_layout);
        mWifiBox = (CheckBox) findViewById(R.id.wifi_check_box);
        mAlwayLayout = (RelativeLayout) findViewById(R.id.alway_layout);
        mAlwayBox = (CheckBox) findViewById(R.id.alway_check_box);
        mNeverLayout = (RelativeLayout) findViewById(R.id.close_layout);
        mNeverBox = (CheckBox) findViewById(R.id.close_check_box);

        mBackView.setOnClickListener(this);
        mWifiLayout.setOnClickListener(this);
        mAlwayLayout.setOnClickListener(this);
        mNeverLayout.setOnClickListener(this);

    }

    private void init() {
        int currentSetting = SPManager.getInstance().getInt(
                SPManager.VIDEO_SETTING, 1);

        switch (currentSetting) {
            case 0:
                choiceAlwayBox();
                break;
            case 1:
                choiceWifiBox();
                break;
            case 2:
                choiceNeverBox();
                break;
            default:
                break;
        }
    }

    private void choiceAlwayBox() {
        mAlwayBox.setBackgroundResource(R.drawable.setting_selected);
        mWifiBox.setBackgroundResource(0);
        mNeverBox.setBackgroundResource(0);
    }

    private void choiceWifiBox() {
        mAlwayBox.setBackgroundResource(0);
        mWifiBox.setBackgroundResource(R.drawable.setting_selected);
        mNeverBox.setBackgroundResource(0);
    }

    private void choiceNeverBox() {
        mAlwayBox.setBackgroundResource(0);
        mWifiBox.setBackgroundResource(0);
        mNeverBox.setBackgroundResource(R.drawable.setting_selected);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.alway_layout:
                SPManager.getInstance().putInt(SPManager.VIDEO_SETTING
                        , 0);
                AdParameters.setCurrentSetting(SDKConstant.AutoPlaySetting.AUTO_PLAY_3G_4G_WIFI);

                choiceAlwayBox();
                break;
            case R.id.wifi_layout:
                SPManager.getInstance().putInt(SPManager.VIDEO_SETTING,
                        1);
                AdParameters.setCurrentSetting(SDKConstant.AutoPlaySetting.AUTO_PLAY_ONLY_WIFI);

                choiceWifiBox();
                break;
            case R.id.close_layout:
                SPManager.getInstance().putInt(SPManager.VIDEO_SETTING,
                        2);
                AdParameters.setCurrentSetting(SDKConstant.AutoPlaySetting.AUTO_PLAY_NEVER);

                choiceNeverBox();
                break;
            case R.id.back_view:
                finish();
                break;
        }
    }
}
